<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">       
        <?php echo link_tag('bootstrap/css/estilo.css') ?>
        <?php echo link_tag('bootstrap/css/bootstrap.min.css') ?>
        <?php echo link_tag('bootstrap/css/layout.css') ?>
        <?php echo link_tag('bootstrap/css/tablascss.css') ?>
    </head>

    <body> 
        <fieldset>          
            <div class="body" id="container">
                <section id="buttonGroups">
                    <div class="page-header">
                        <h1>Registro Venta de Tarjetas</h1>
                    </div>
                    <div class="row">
                        <div class="span8">
                            <form class="form-horizontal" method="POST" action="/simertweb/estadisticas_tarjetas/registroVenta">
                                <div class="control-group">
                                    <p>Elija el intervalo de fecha de consulta:</p><br>
                                    Desde:
                                    &nbsp;
                                    <input type="date" name="fecInicio" class="input-medium" style="margin-left: 20px" 
                                           value="<?php date_default_timezone_set('America/Guayaquil'); echo date('Y-m-d'); ?>">
                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    Hasta:&nbsp;                           
                                    <input type="date" name="fecFin" class="input-medium" style="margin-left: 20px"  
                                           value="<?php date_default_timezone_set('America/Guayaquil'); echo date('Y-m-d'); ?>">
                                </div> 

                                <div class="span7">
                                    <button type="submit" class="btn btn-primary">Calcular</button>
                                </div>
                                <br>
                                <?php
                                $cadena = 0;
                                if (isset($ventas) == FALSE) {
                                    ?>
                                    <br>
                                    <b>Información de Tarjetas Vendidas</b><br><br>
                                    <div class="datagrid" style="margin-right: -80px;margin-left: -20px">
                                        <table  class="table" border=2 style=" overflow-y: scroll" >  
                                            <tr>                                                        
                                                <td bgcolor="#CCCOCC"><center><B>Cantidad</B></center></td>
                                                <td bgcolor="#CCCOCC"><center><B>Serie</B></center></td>
                                                <td bgcolor="#CCCOCC"><center><B>Precio Unitario</B></center></td>
                                                <td bgcolor="#CCCOCC"><center><B>Subtotal</B></center></td>
                                                <td bgcolor="#CCCOCC"><center><B>Descuento(%)</B></center></td>
                                                <td bgcolor="#CCCOCC"><center><B>Total Descuento</B></center></td>
                                                <td bgcolor="#CCCOCC"><center><B>Total</B></center></td>
                                            </tr>
                                            <tr>
                                                <td></td><td></td><td></td><td></td>
                                                <td></td><td></td><td></td>
                                            </tr>
                                            <tr>
                                                <td></td><td></td><td></td><td></td>
                                                <td></td><td></td><td></td>
                                            </tr>
                                            <tr>
                                                <td></td><td></td><td></td><td></td>
                                                <td></td><td></td><td></td>
                                            </tr>
                                        </table>
                                    </div>
                                <?php } elseif (is_string($ventas)) { ?>
                                    <?php ?>

                                    <p> <font color="red">AVISO: INGRESE LAS FECHAS CORRECTAMENTE</font></p><br>
                                    <P> <b>Información de las Tasas</b></P>
                                    <div class="datagrid" style="margin-right: -80px;margin-left: -20px">
                                        <table  class="table" border=2 style=" overflow-y: scroll" >  
                                            <tr FONT FACE="arial">                                                        
                                                <td  bgcolor="#CCCOCC"><center><B>Cantidad</B></center></td>
                                                <td  bgcolor="#CCCOCC"><center><B>Serie</B></center></td>
                                                <td  bgcolor="#CCCOCC"><center><B>Precio Unitario</B></center></td>
                                                <td  bgcolor="#CCCOCC"><center><B>Subtotal</B></center></td>
                                                <td  bgcolor="#CCCOCC"><center><B>Descuento(%)</B></center></td>
                                                <td  bgcolor="#CCCOCC"><center><B>Total Descuento</B></center></td>
                                                <td  bgcolor="#CCCOCC"><center><B>Total</B></center></td>
                                            </tr>

                                            <tr>
                                                <td></td><td></td><td></td><td></td>
                                                <td></td><td></td><td></td>
                                            </tr>
                                            <tr>
                                                <td></td><td></td><td></td><td></td>
                                                <td></td><td></td><td></td>
                                            </tr>
                                            <tr>
                                                <td></td><td></td><td></td><td></td>
                                                <td></td><td></td><td></td>
                                            </tr>

                                        </table>
                                    </div>
                                    <?php
                                } elseif ($ventas != null) {


                                    $fecha = $ventas[0]['fecha'];
                                    $cadena = strlen($ventas[0]['fecha']);
                                    if ($cadena == 10) {
                                        ?>
                                        <br>
                                        <font color=#002166>  <b>Fecha:&nbsp;&nbsp; </b><?php echo $fecha ?> </font> <br> <br>
                                            <div class="datagrid" style="margin-right: -80px;margin-left: -20px">
                                                <table  class="table" border=2 style=" overflow-y: scroll" >  
                                                    <tr>                                                        
                                                        <td  bgcolor="#CCCOCC"><center><B>Cantidad</B></center></td>
                                                        <td  bgcolor="#CCCOCC"><center><B>Serie</B></center></td>
                                                        <td  bgcolor="#CCCOCC"><center><B>Precio Unitario</B></center></td>
                                                        <td  bgcolor="#CCCOCC"><center><B>Subtotal</B></center></td>
                                                        <td  bgcolor="#CCCOCC"><center><B>Descuento(%)</B></center></td>
                                                        <td  bgcolor="#CCCOCC"><center><B>Total Descuento</B></center></td>
                                                        <td  bgcolor="#CCCOCC"><center><B>Total</B></center></td>
                                                    </tr>

                                                    <?php
                                                    $tcant = 0;
                                                    $tprecio = 0;
                                                    $tdesc = 0;
                                                    $ttotal = 0;
                                                    for ($i = 0; $i < count($ventas); ++$i) {
                                                        $cant = $ventas[$i]['cantidad'];
                                                        $tcant += $cant;
                                                        $serie = $ventas[$i]['serie'];
                                                        $unitario = $ventas[$i]['precio'];
                                                        $precio = $ventas[$i]['precio'] * $cant;
                                                        $n = $tprecio += $precio;
                                                        $descuento = ($ventas[$i]['desc'] );
                                                        $desc = $ventas[$i]['tdesc'];
                                                        $tdesc += $desc;
                                                        $total = $ventas[$i]['total'];
                                                        $ttotal += $total;
                                                        ?>
                                                    <tr>
                                                        <td><center><?php echo $cant ?></center></td>
                                                        <td><center><?php echo $serie ?></center></td>
                                                        <td><center><?php echo $unitario ?></center></td>
                                                        <td><center><?php echo $precio ?></center></td>
                                                        <td><center><?php echo $descuento ?></center></td>
                                                        <td><center><?php echo $desc ?></center></td>
                                                        <td><center><?php echo $total ?></center></td>                       
                                                    </tr>
                                                <?php } ?> 
                                                <tr>
                                                    <td><center>=</center></td>
                                                    <td><center></center></td>
                                                    <td><center></center></td>
                                                    <td><center>=</center></td>
                                                    <td><center></center></td>
                                                    <td><center>=</center></td>
                                                    <td><center><b>=<br></center></td>
                                                </tr>
                                                <tr>
                                                    <td bgcolor=#58FA58><center><b><?php echo $tcant ?></b></center></td>
                                                    <td bgcolor=#58FA58><center></center></td>
                                                    <td bgcolor=#58FA58><center></center></td>
                                                    <td bgcolor=#58FA58><center><b><?php echo $tprecio ?></b></center></td>
                                                    <td bgcolor=#58FA58><center></center></td>
                                                    <td bgcolor=#58FA58><center><b><?php echo $tdesc ?></b></center></td>
                                                    <td bgcolor=#58FA58><center><b><?php echo $ttotal ?></b></center></td>
                                                </tr>
                                        </table>
                                    </div>
                            <?php } elseif ($cadena > 10) {?>
                                        <br>
                                        <font color=#002166>  <b>Fecha:&nbsp;&nbsp; </b><?php echo $fecha ?> </font> <br> <br>
                                        <div class="datagrid" style="margin-right: -80px;margin-left: -20px">
                                            <table  class="table" border=2 style=" overflow-y: scroll" >  
                                                <tr>                                                        
                                                    <td bgcolor="#CCCOCC"><B><center>Valor</center></B></td>
                                                    <td  bgcolor="#CCCOCC"><center><B>Cantidad</B></center></td>
                                                    <td bgcolor="#CCCOCC"><B><center>Subtotal</center></B></td>
                                                    <td  bgcolor="#CCCOCC"><B><center>Descuento</center></B></td>
                                                    <td bgcolor="#CCCOCC"><B><center>Total</center></B></td>
                                                </tr>
                                                <?php
                                                $cant1 = $ventas[0]['cant1'];
                                                $cant2 = $ventas[0]['cant2'];
                                                $cant3 = $ventas[0]['cant3'];
                                                $desc1 = $ventas[0]['descuento1'];
                                                $desc2 = $ventas[0]['descuento2'];
                                                $desc3 = $ventas[0]['descuento3'];
                                                $total1 = $ventas[0]['total1'];
                                                $total2 = $ventas[0]['total2'];
                                                $total3 = $ventas[0]['total3'];
                                                $precio1 = $ventas[0]['precio1'];
                                                $precio2 = $ventas[0]['precio2'];
                                                $precio3 = $ventas[0]['precio3'];
                                                ?>
                                            <tr>
                                                <td><center><?php echo '0%' ?></center></td>
                                            <td><center><?php
                                            if (empty($cant1)) {
                                                echo '-';
                                            } else {
                                                echo $cant1;
                                            }
                                                    ?></center></td>
                                                    <td><center><?php
                                                if (empty($precio1)) {
                                                    echo '-';
                                                } else {
                                                    echo $precio1;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($desc1)) {
                                                echo '0';
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($total1)) {
                                                echo '-';
                                            } else {
                                                echo $total1;
                                            }
                                                ?></center></td>
                                                </tr>
                                                <tr>
                                                    <td><center><?php echo '5%' ?></center></td>
                                                <td><center><?php
                                            if (empty($cant2)) {
                                                echo '-';
                                            } else {
                                                echo $cant2;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($precio2)) {
                                                echo '-';
                                            } else {
                                                echo $precio2;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($desc2)) {
                                                echo '-';
                                            } else {
                                                echo $desc2;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($total2)) {
                                                echo '-';
                                            } else {
                                                echo $total2;
                                            }
                                                ?></center></td>
                                                </tr>
                                                <tr>
                                                    <td><center><?php echo '15%' ?></center></td>
                                                <td><center><?php
                                            if (empty($cant3)) {
                                                echo '-';
                                            } else {
                                                echo $cant3;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($precio3)) {
                                                echo '-';
                                            } else {
                                                echo $precio3;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($desc3)) {
                                                echo '-';
                                            } else {
                                                echo $desc3;
                                            }
                                                ?></center></td>
                                                <td><center><?php
                                            if (empty($total3)) {
                                                echo '-';
                                            } else {
                                                echo $total3;
                                            }
                                                ?></center></td>
                                                </tr>

                                            </table>
                                        </div>
                                        <?php
                                    }
                                } else {
                                    $fecha = 'No existen consultas.';
                                    ?>
                                    <br>
                                    <font color=#002166>  <b>Fecha:&nbsp; </b><?php echo $fecha ?> </font> <br> <br>
                                    <div class="datagrid" style="margin-right: -80px;margin-left: -20px">
                                        <table  class="table" border=2 style=" overflow-y: scroll" >  
                                            <tr>                                                        
                                                <td bgcolor="#CCCOCC"><B><center>Descuento</center></B></td>
                                                <td bgcolor="#CCCOCC"><center><B>Cantidad</B></center></td>
                                                <td bgcolor="#CCCOCC"><B><center>Subtotal</center></B></td>
                                                <td bgcolor="#CCCOCC"><B><center>Total Descuento</center></B></td>
                                                <td bgcolor="#CCCOCC"><B><center>Total</center></B></td>
                                            </tr>                                                          
                                        </table>
                                    </div>
                                <?php } ?>
                            </form>
                            
                            <form method="POST" target="_blank" action="/simertweb/estadisticas_tarjetas/generar_venta_tarjetas">
                                <input class="invisible" type="text" class="input-medium" name="fechai" 
                                       value="<?php if(isset($fechas[0])){echo $fechas[0];}else{date_default_timezone_set('America/Guayaquil'); echo date('Y-m-d');} ?>" >
                                <input class="invisible" type="text" class="input-medium" name="fechaf" 
                                       value="<?php if(isset($fechas[1])){echo $fechas[1];}else{date_default_timezone_set('America/Guayaquil'); echo date('Y-m-d');} ?>" ><br>
                                <button type="submit" class="btn btn-primary">Imprimir</button>
                            </form>
                        </div>
                    </div>
                </section> 
            </div>
        </fieldset>
    </body>
</html>
